Model Inheritance

  • Step 1:

    Example 1

    
                  from odoo import fields, models
    
    class InheritedModel(models.Model):
        _inherit = "inherited.model"
    
        new_field = fields.Char(string="New Field")
    
    
    
    
    <record id="inherited_model_view_form" model="ir.ui.view">
        <field name="name">inherited.model.form.inherit.test</field>
        <field name="model">inherited.model</field>
        <field name="inherit_id" ref="inherited.inherited_model_view_form"/>
        <field name="arch" type="xml">
            <!-- find field description and add the field
                 new_field after it -->
            <xpath expr="//field[@name='description']" position="after">
              <field name="new_field"/>
            </xpath>
        </field>
    </record>
    
    
    to get inherited.inherited_model_view_form
    1. enable developer mode
    2. go to view form of parent module
    3. go to edit form option
    4. inspect external ID option

    Example 2

    
    from odoo import models, fields
    
    class SaleOrderInherited(models.Model):
        _inherit = 'sale.order' 
    
        custom_field = fields.Char(string='Custom Field')
    
    
    
    <record id="view_sale_order_custom" model="ir.ui.view"> 
    <field name="name">sale.order.custom.form.inherited</field>
         <field name="model">sale.order</field> 
         <field name="inherit_id" ref="sale.view_order_form"/> 
         <field name="arch" type="xml"> 
              <xpath expr="//field[@name='partner_id']" position="after"> 
                   <field name="custom_field"/>
              </xpath> 
         </field> 
    </record>